package com.apress.prospringmvc.bookstore.web.controller;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.apress.prospringmvc.bookstore.domain.Book;
import com.apress.prospringmvc.bookstore.service.BookstoreService;

@Controller
@RequestMapping(value = "/hello_list")
public class HelloController {
	
	private transient final Log log = LogFactory.getLog(HelloController.class);
	@Autowired
	private BookstoreService mgr = null;

	@ResponseBody
	public String helloList() {
		StringBuilder str = new StringBuilder("{totalProperty:100,root:[");

		List<Book> users = mgr.findRandomBooks();
		for (Book user : users) {
			str.append("{id: ").append(user.getId());
			str.append(", name:'").append(user.getTitle());
			str.append("', descn:'").append(user.getIsbn()).append("'},");
		}
		str.append("{id:4, name:'생활', descn:'Китай'},");
		str.append("{id:5, name:'tchen8', descn:'中文'}]}");

		log.info(str.toString());

		return str.toString();
	}

}
